function FViz() { }
FViz.LAYTOUT_ABSLOUTE = 1;//大屏设计模式

$(function () {
  $(document).on('click', function () {
    $(".fviz-container-bg").removeClass("fviz-container-bg");
  })
})

function fvizMessager(title, message) {
  $.messager.show({
    title: title,
    msg: message,
    showType: 'show',
    timeout: 2000,
    style: {
      left: '',
      right: 0,
      top: document.body.scrollTop + document.documentElement.scrollTop,
      bottom: ''
    }
  });
}

var fvizMixin = {
  props: {

    objVal: { //所有配置信息
      type: Object,
      default: function () {
        return {}
      }
    },
    refreshable: { //在设计器中拖拽、调整尺寸避免二次刷新控制
      type: Boolean,
      default: function () {
        return true;
      }
    },
    preview: {//是否预览模式
      type: Boolean,
      default: function () {
        return false;
      }
    },
    queryParams: { //所有配置信息
      type: Function
    }
  },
  methods: {
    bindDrag(refId) { //绑定拖拽
      let me = this;
      if (FViz.LAYTOUT_ABSLOUTE == this.objVal.layoutMode) {
        $(this.$refs[refId]).draggable({
          onDrag: function (e) {
            var d = e.data;
            if (d.left < 0) { d.left = 0 }
            if (d.top < 0) { d.top = 0 }
            if (d.left + $(d.target).outerWidth() > $(e.data.parent.parentElement.parentElement).width()) {
              d.left = $(e.data.parent.parentElement.parentElement).width() - $(d.target).outerWidth();
            }
            if (d.top + $(d.target).outerHeight() > $(e.data.parent.parentElement.parentElement).height()) {
              d.top = $(e.data.parent.parentElement.parentElement).height() - $(d.target).outerHeight();
            }
          },
          onStopDrag: function (e) {

            me.refreshable = false;

            let left = $(this).position().left;
            let top = $(this).position().top;

            me.$emit('change-pos', {
              left: _.round(left),
              top: _.round(top)
            })
          }
        });
      }
    },
    bindResize(refId) { //改变尺寸
      let me = this;
      if (FViz.LAYTOUT_ABSLOUTE == this.objVal.layoutMode) {
        $(this.$refs[refId]).resizable({
          onStopResize: function (e) {

            me.refreshable = false;

            let width = $(this).width();
            let height = $(this).height();

            me.$emit('change-size', {
              width: _.round(width),
              height: _.round(height)
            })
          }
        });
      }
    }
  }
}

export {
  fvizMixin, FViz
};